		$('#headbox').load('php/header.php');
		$('#footbox').load('php/footer.php');
		jQuery.validator.addMethod('cellphone',function(value){
		  var reg = /^1[3578]\d{9}$/;
		  return reg.test(value);
		});
		//对选定的表单执行输入验证
		$('#form').validate({
		  //指定每个输入的验证规则
		  rules:{
			useName: {
			  required:true,
			  minlength: 4,
			  maxlength: 12
			},
			pwd: {
			  required: true,
			  minlength: 6,
			  maxlength: 18
			},
			pwdAgain: {
			  required: true,
			  equalTo: "#pwd"//"#pwd"为id名
			},
			phone: {
			  cellphone: true
			},
			inviteCode:{
				digits:true
			},
		  },  
		  //验证失败后的提示信息
		  messages:{
			useName: {
			  required: '用户名不能为空',
			  minlength:'用户名在4~12位字符之间',
			  maxlength:'用户名在4~12位字符之间'
			},
			pwd: {
			  required: '密码不能为空',
			  minlength: '密码太短了',
			  maxlength: '密码太长了'
			},
			pwdAgain: {
			  required: '两次输入的密码不一致',
			  equalTo: '两次输入的密码不一致'
			},
			phone: {
			  cellphone: '手机号码格式不对'
			},
			inviteCode:{
				digits:'邀请码格式不对'
			},
		  }
		});
		/******异步请求验证用户名、手机号******/
		$('#form [name="useName"]').keyup(function(){
			var n=$('#form [name="useName"]').val();
			if(n.length>=4&&n.length<=12){
				$.post('php/users.php',{'uname':n},function(data){
					if(data.length>0){
						$('.alt_name').html('该用户名已注册');
					}else{
						$('.alt_name').html('该用户名可用');
					}
				});
			}else{
				$('.alt_name').html('');
			}
		});
		$('#form [name="phone"]').keyup(function(){
			var p=$('#form [name="phone"]').val();
			var reg=/^1[3,5,7,8]{1}[0-9]{9}$/;
			if(reg.test(p)){
				$.post('php/uphone.php',{'uphone':p},function(data){
					if(data.length>0){
						$('.alt_phone').html('手机号码已存在');
					}else{
						$('.alt_phone').html('手机号码可用');
					}
				});
			}else{
				$('.alt_phone').html('');
			}
		});
		/****模拟验证码****/
		function code(){
			var c=Math.floor(Math.random()*9000+1000);
			return c;
		};
		$(function(){
			$('#code').html( code() );
		});
		$('#code').click(function(){
			$('#code').html( code() )
		});
		/******自定义验证码验证******/
		$('#form [name="chkWord"]').blur(function(){
			if($(this).val()!=''){
				if($(this).val()!=$('#code').html()){
					$('#sp').html("验证码不对");
					$(this).focus().css('color','#f60');
				}else{
					$('#sp').empty();
					$(this).css('color','#666');
				}
			}
		});
		/*****注册账户******/
		$('#form [type="button"]').click(function(){
			var uname=$('#form [name="useName"]').val();
			var upwd=$('#form [name="pwd"]').val();
			var uphone=$('#form [name="phone"]').val();
			var inviteCode=$('#form [name="inviteCode"]').val();
			if($('#form input:not([name="inviteCode"])').val().length>0&&$('#form [name="chkWord"]').val()==$('#code').html()){
				$.get('php/submit.php',{'uname':uname,'upwd':upwd,'uphone':uphone,'inviteCode':inviteCode},function(data,msg){
					if(data=="eroor"){
						alert("该用户已注册,请重新注册！");
					}else if(data=="yes"){
						//注册成功提示框
						$('.modal').show();
						//5秒后自动跳转到首页
						function calc(){
							var n=parseInt($('#tip').html());
							n--;
							if(n>0){
								$('#tip').html(n+"&nbsp;&nbsp;秒钟后跳转到首页");
							}else{
								$('head').append(`
									<meta http-equiv='refresh' content='0;url=index.html'>
								`);
							}
						}
						var timer=setInterval(calc,1000);
						function clear(){
							$('.modal').hide();
							clearInterval(timer);
						}
						$('#location a').click(function(e){
							e.preventDefault();
							$('.alt_name,.alt_phone').empty();
							$('#form input:not([type="button"])').val('');
							clear();
						});
					}
				});
			};
		});
